#ifndef __STM32_FLASH_H__
#define __STM32_FLASH_H__

/*
STM32F103xC
	FLASH:256KB
	RAM:48KB
STM32F103xD
	FLASH:384KB
	RAM:64KB
STM32F103xE
	FLASH:512KB
	RAM:64KB
*/
#define SIZE_1KB 1024

#define FLASH_PAGE_SIZE (SIZE_1KB*2)
#define FLASH_TYPE_256KB 256
#define FLASH_TYPE_384KB 384
#define FLASH_TYPE_512KB 512
#define FLASH_TYPE FLASH_TYPE_384KB
#define FLASH_TOTAL_SIZE (FLASH_TYPE*FLASH_PAGE_SIZE)

#define RAM_TYPE_48KB 48
#define RAM_TYPE_64KB 64
#define RAM_TYPE RAM_TYPE_64KB
#define RAM_TOTAL_SIZE (RAM_TYPE*SIZE_1KB) //

/*1:3:1:3*/
#define FLASH_BASE_UINT (FLASH_TYPE/(2*8))

#define FLASH_BLOCK_BOOT_SIZE FLASH_PAGE_SIZE*FLASH_BASE_UINT
#define FLASH_BLOCK_APP_SIZE FLASH_PAGE_SIZE*FLASH_BASE_UINT*3
#define FLASH_BLOCK_INFO_SIZE FLASH_PAGE_SIZE*FLASH_BASE_UINT
#define FLASH_BLOCK_BACK_SIZE FLASH_PAGE_SIZE*FLASH_BASE_UINT*3

typedef enum {
	FLASH_BASE_BOOT=FLASH_BASE,
	FLASH_BASE_APP=FLASH_BASE_BOOT+FLASH_BLOCK_BOOT_SIZE,
	FLASH_BASE_INFO=FLASH_BASE_APP+FLASH_BLOCK_APP_SIZE,
	FLASH_BASE_BACK=FLASH_BASE_INFO+FLASH_BLOCK_INFO_SIZE,
	FLASH_BASE_BUTT=FLASH_BASE_BACK+FLASH_BLOCK_BACK_SIZE
}FLASH_MAP_E;

#if 0
#define VNIC_VECT_TAB_OFFSET FLASH_BASE_APP
#else
#define VNIC_VECT_TAB_OFFSET 0x0
#endif

typedef enum{
	FLASH_INFO_PRODUCT=FLASH_BASE_INFO,
	FLASH_INFO_PRODUCT_BACK=FLASH_BASE_INFO+FLASH_PAGE_SIZE,			
	FLASH_INFO_UPDATE_PARAM=FLASH_INFO_PRODUCT_BACK+FLASH_PAGE_SIZE,
	FLASH_INFO_UPDATE_PARAM_BACK=FLASH_INFO_UPDATE_PARAM+FLASH_PAGE_SIZE,	
	FLASH_INFO_BUTT=FLASH_BASE_INFO+FLASH_BLOCK_INFO_SIZE
}FLASH_INFO_MAP_E;


int32_t stm32_flash_read(uint32_t addr, uint8_t *buf, uint32_t len );
int32_t stm32_flash_write(uint32_t addr, uint8_t *buf, uint32_t len);
int32_t stm32_flash_erase(uint32_t addr, uint32_t page_num);

#endif

